/******************************************************************************
 * Copyright (C) 2024 Createtree, Inc.(Gmbh) or its affiliates.
 *
 * All Rights Reserved.
 *
 * @file system_adaption.h
 *
 * @par dependencies
 * - stdio.h
 * - stdint.h
 * - bsp_led_driver.h
 * - bsp_led_handler.h
 * @author Createtree | R&D Dept. | liuzhihuawy@163.com
 *
 * @brief Intergrate all the resources of system and enable the system to run.
 *
 * Processing flow:
 *
 * call directly.
 *
 * @version V1.0 2024-11-01
 *
 * @note 1 tab == 4 spaces!
 *
 *****************************************************************************/
#ifndef __SYSTEM_ADAPTION_H__ // Avoid repeated including same files later
#define __SYSTEM_ADAPTION_H__
//******************************** Includes *********************************//
#include <stdint.h>
#include <stdio.h>

#include "bsp_led_driver.h"
#include "bsp_led_handler.h"

//******************************** Includes *********************************//

//******************************** Defines **********************************//
// #define SYSTEM_UNIT_TESTING
#define SYSTEM_INIT_PATTERN 0x5A
typedef enum
{
    SYSTEM_STATUS_OK           =    0,  /* System operation is successful    */
    SYSTEM_STATUS_ERROR        =    1,  /* System operation is failed        */
    SYSTEM_SATUS_RESERVED      = 0xFF,  /* Reserved                          */
} system_status_t;



//******************************** Defines **********************************//

//******************************** Declaring ********************************//
extern bsp_led_handler_t led_handler1;
extern bsp_led_driver_t led_driver1;
extern led_id_t hled1;


/* BSP driver interface ---------------------------------*/
led_status_t led1_on(void);
led_status_t led1_off(void);
extern const led_operations_t led1_ops_handle;

led_status_t test_get_time(uint32_t * const ms);
extern const time_base_t test_time_base_handle;

led_status_t test_os_sleep(const uint32_t ms);
extern const os_sleep_t test_os_sleep_handle;


/* LED Handler interface --------------------------------*/
#ifdef OS_SUPPORTING
led_handler_status_t fn_led_handler1_os_sleep(const uint32_t ms);
extern const handler_os_sleep_t led_handler1_os_sleep;

/* os queue create */
led_handler_status_t fn_led_handler1_os_queue_create (
                                            uint32_t const       cell_num,
                                            uint32_t const      cell_size,
                                            void **  const   queue_handle);

/* os queue send */
led_handler_status_t fn_led_handler1_os_queue_push  (
                                            void  *   const   queue_handle,
                                            void  *   const            msg,
                                            uint32_t               timeout);

/* os queue receive */
led_handler_status_t fn_led_handler1_os_queue_pop   (
                                            void  *   const   queue_handle,
                                            void  *   const            msg,
                                            uint32_t               timeout);

/* os queue delete */
led_handler_status_t fn_led_handler1_os_queue_delete (
                                           void  *   const   queue_handle);

extern const handler_os_queue_op_t led_handler1_os_queue_op;

/* entry critical section */
void fn_led_handler1_os_critical_enter (void);
/* exit critical section */
void fn_led_handler1_os_critical_exit  (void);
extern const handler_os_critial_t led_handler1_os_critical;

/* os thread create */
led_handler_status_t fn_led_handler1_os_therad_create (
                        void *   const       task_fn,
                        const char        *task_name,
                        uint32_t const    stack_size,
                        void *   const    parameters,
                        uint32_t const      priority,
                        void **  const   task_handle);
/* os thread delete */
led_handler_status_t fn_led_handler1_os_thread_delete (
                        void *   const   task_handle);
extern const handler_os_thread_op_t led_handler1_os_thread_op;
#endif /* OS_SUPPORTING */

led_handler_status_t fn_led_handler1_get_time(uint32_t * const ms);
extern const handler_time_base_t led_handler1_time_base;

#ifdef SYSTEM_UNIT_TESTING
void test_led_driver(void);
void test_led_handler(void);
#endif  /* SYSTEM_UNIT_TESTING */

system_status_t system_adaption_init(void);

//******************************** Declaring ********************************//

#endif /* __SYSTEM_ADAPTION_H__ */
